package com.lemon.controller;

import com.lemon.domain.PageResult;
import com.lemon.domain.Result;
import com.lemon.domain.Sku;
import com.lemon.domain.dto.SpuDto;
import com.lemon.domain.pageParam.SpuPageParam;
import com.lemon.service.SpuService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/spu")
public class SpuController {

    @Autowired
    private SpuService spuService;

    @GetMapping("/sku")
    public Result getSkuList() {
        List<Sku> list = spuService.getSkuList();
        return Result.success(list);
    }


    @GetMapping
    @Operation(description = "查询所有商品")
    public Result getList(SpuPageParam spuPageParam) {
        PageResult list = spuService.getAll(spuPageParam);
        return Result.success(list);
    }

    @PostMapping
    @Operation(description = "添加商品")
    public Result add(@RequestBody SpuDto spuDto) {
        spuService.add(spuDto);
        return Result.success();
    }

    @PutMapping
    @Operation(description = "修改商品")
    public Result update(@RequestBody SpuDto spuDto) {
        spuService.updateSpu(spuDto);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @Operation(description = "删除商品")
    public Result delete(@PathVariable Integer id) {
        spuService.deleteSpu(id);
        return Result.success();
    }
}
